package com.bbs.util.web;

import java.io.IOException;
import java.util.Properties;

import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
public class EmailUtil {

	private static String HOST;
	private static String FromAddress;
	private static String NAME;
	private static String PASSORD;
	
	static{
		Properties pro = new Properties();
		try {
			pro.load(Email.class.getClassLoader().getResourceAsStream("email.properties"));
			HOST = pro.getProperty("host");
			FromAddress = pro.getProperty("address");
			NAME = pro.getProperty("name");
			PASSORD = pro.getProperty("password");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void sendEmail(String address, String title, String msg) throws EmailException {

		Email mail = new SimpleEmail();
		mail.setHostName(HOST);
		mail.setAuthentication(NAME, PASSORD);
		mail.setTLS(true);
		mail.setCharset("UTF-8");
		
		mail.setFrom(FromAddress);
		mail.setSubject(title);
		mail.setMsg(msg);
		mail.addTo(address);
		mail.send();
	}
}
